#comments-start - More Info Dialog
[SCRIPT NAME]Copy Clipboard Text To File
Description:
    - Copies content from the clipboard and writes it to a new line in the specified file.
        - Notes:
            - If the folder or file doesn't exist, they will be created

Arguments:
    - Arg1: Path to target file (Required) - e.g. C:\MyFiles\myfile.txt
    - Arg2: Overwrite existing files flag [Optional]
        - Options:
            - 9 = Create directory and file or append to existing (Default)
            - 10 = Create directory and file or overwrite existing
#comments-end - More Info Dialog

#include <Include\WinClickPro.au3>
#include <Include\File.au3>
#include <Include\ClipBoard.au3>

Func Main()
	Local $sFilePath = ""
	Local $sFlag = 9 ; Default which creates the directory and file and/or appends the content.
	Local $sClipGet  = ""
	Local $fileHandle

	;
	; This script has 1 required argument and 1 optional.
	;
	If $CmdLine[0] < 1 Then
		_DisplayErrorAndExit("Invalid argument count detected!" & @LF & "Count: " & $CmdLine[0])
	EndIf

	$sFilePath = $CmdLine[1];

	;
	; Did the user specify a flag?
	;
	If $CmdLine[0] == 2 Then
		$sFlag = $CmdLine[2]

		If $sFlag == "" Then
			$sFlag = 9; User passed in a blank Arg, reset to default.
		EndIf

		;
		; Any flag value other than 9 or 10 is considered invalid
		;
		If $sFlag < 9 Or $sFlag > 10 Then
			_DisplayErrorAndExit("Invalid value specified the overwrite flag. Expecting 9 or 10!" & @LF & "Actual: " & $sFlag)
		EndIf
	EndIf

	$sClipGet = ClipGet() ; Get whatever content is on the clipboard

	;
	; If nothing to copy, no point in going on.
	; We quietly fail because a user might prefer that behavior.
	; TODO: Return an error code which we can then optionally notify the user with.
	;
	If $sClipGet == "" Then
		Exit ; Not considered an error
	EndIf

	$fileHandle = FileOpen($sFilePath, $sFlag)
	FileWriteLine($fileHandle, $sClipGet)
	FileClose($fileHandle)
EndFunc

Main()
Exit @error